//
// Created by 吴喆 on 2020/3/25.
//

#include "DemoBullet.h"
#include "DemoMonster.h"
#include "DemoBulletParticleGenerator.h"

DemoBullet::DemoBullet(const Scene *scene, Playable *parent, const glm::vec2 &startPosition)
        : Bullet(scene, parent, startPosition) {
    Bullet::init();
}

void DemoBullet::onTouched(GameObject *gameObject) {
    auto monster = dynamic_cast<DemoMonster *>(gameObject);
    if (monster) {
        isContacted = true;
        monster->beAtked(harm);
    }
}

void DemoBullet::initStateMachine() {
    Playable::machines.emplace_back(new BulletStateMachine);
}

void DemoBullet::render() {
    renderer->DrawSprite(scene->getCamera(), currentAnimation->updateAndGetCurrentFrame(), GameObject::currPosition,
                        GameObject::size, 0.0f,
                        Playable::direction == DIRECTION::LEFT);
    particleGenerator->render(*renderer);
}

void DemoBullet::update() {
    Bullet::update();
    particleGenerator->update();
}

void DemoBullet::initParticleGenerator() {
    particleGenerator = new DemoBulletParticleGenerator(ResourceManager::getTexture("tile.Overworld Tiles 8x_150.png"), this, 40);
}
